home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Shareware City / Games / Jotto ][ 1.1.source Folder / Jotto ][ ƒ / Shell ƒ / about.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-06  |  5.3 KB  |  203 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles displaying the about box.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "graphics.h"        /* needs to come first because it defines WindowDataHandle */
  25. #include "about.h"
  26. #include "prefs.h"
  27. #include "util.h"
  28.  
  29. /*-----------------------------------------------------------------------------------*/
  30. /* internal stuff for about.c                                                        */
  31.  
  32. void SetupTheAboutBox(WindowDataHandle theData);
  33. void InitializeTheAboutBox(WindowDataHandle theData);
  34. void OpenTheAboutBox(WindowDataHandle theData);
  35. void ResizeTheAboutBox(WindowDataHandle theData);
  36. void ShutdownTheAboutBox(WindowDataHandle theData);
  37. void DrawTheAboutBox(Boolean isColor);
  38. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  39. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter);
  40.  
  41. Boolean            gUseAlternate;
  42. PicHandle        gTheAboutPict;
  43.  
  44. enum
  45. {
  46.     kAboutColorPictID=134,
  47.     kAboutBWPictID
  48. };
  49.  
  50. short AboutBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  51. {
  52.     short            theDepth;
  53.     
  54.     switch (theMessage)    /* see graphics.h for list of messages*/
  55.     {
  56.         case kKeydown:                            /* close about box on keypress */
  57.         case kMousedown:                        /* or mouseclick */
  58.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  59.             return kSuccess;
  60.             break;
  61.         case kUpdate:
  62.             theDepth=misc&0x7fff;                /* pixel depth */
  63.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  64.             return kSuccess;
  65.             break;
  66.         case kInitialize:
  67.             InitializeTheAboutBox(theData);
  68.             return kFailure;
  69.         case kOpen:
  70.             OpenTheAboutBox(theData);
  71.             return kSuccess;
  72.             break;
  73.         case kStartup:
  74.             SetupTheAboutBox(theData);
  75.             return kSuccess;
  76.             break;
  77.         case kShutdown:
  78.             ShutdownTheAboutBox(theData);
  79.             return kSuccess;
  80.             break;
  81.         case kChangeDepth:
  82.             gTheAboutPict=ReleaseThePict(gTheAboutPict);
  83.             return kSuccess;
  84.             break;
  85.     }
  86.     
  87.     return kFailure;        /* for all other messages, defer to default processing */
  88. }
  89.  
  90. void SetupTheAboutBox(WindowDataHandle theData)
  91. {
  92.     unsigned char    *theTitle="\pAbout Jotto ][";
  93.     
  94.     (**theData).windowType=noGrowDocProc;    /* plain vanilla window */
  95.     Mymemcpy((Ptr)((**theData).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  96.     (**theData).hasCloseBox=TRUE;
  97.     (**theData).maxDepth=8;
  98.     (**theData).windowWidth=300;
  99.     (**theData).windowHeight=235;
  100.     gUseAlternate=FALSE;
  101.     gTheAboutPict=0L;
  102. }
  103.  
  104. void InitializeTheAboutBox(WindowDataHandle theData)
  105. {
  106. }
  107.  
  108. void OpenTheAboutBox(WindowDataHandle theData)
  109. {
  110.     KeyMap            rawKeys;
  111.     unsigned short    theKeys[8];
  112.     
  113.     GetKeys(rawKeys);
  114.     Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
  115.     if (theKeys[3]&4)    /* option key down? */
  116.     {
  117.         if (!gUseAlternate)
  118.         {
  119.             gUseAlternate=TRUE;
  120.             (**theData).offscreenNeedsUpdate=TRUE;
  121.         }
  122.     }
  123.     else
  124.     {
  125.         if (gUseAlternate)
  126.         {
  127.             gUseAlternate=FALSE;
  128.             (**theData).offscreenNeedsUpdate=TRUE;
  129.         }
  130.     }
  131. }
  132.  
  133. void ShutdownTheAboutBox(WindowDataHandle theData)
  134. {
  135.     gTheAboutPict=ReleaseThePict(gTheAboutPict);
  136. }
  137.  
  138. void DrawTheAboutBox(Boolean isColor)
  139. {
  140.     RGBColor        oldForeColor, oldBackColor;
  141.     short            row;
  142.     Handle            textHandle;
  143.     Str255            theLine;
  144.     unsigned long    pos;
  145.     unsigned long    theSize;
  146.     GrafPtr            curPort;
  147.     short            theCenter;
  148.     
  149.     GetPort(&curPort);
  150.     FillRect(&(curPort->portRect), black);
  151.     TextMode(srcXor);
  152.     
  153.     gTheAboutPict=DrawThePicture(gTheAboutPict, isColor ?
  154.         kAboutColorPictID : kAboutBWPictID, 0, 10);
  155.     
  156.     theCenter=(curPort->portRect.right-curPort->portRect.left)/2;
  157.     
  158.     TextFont(geneva);
  159.     TextSize(9);
  160.     row=(**gTheAboutPict).picFrame.bottom-(**gTheAboutPict).picFrame.top+30;
  161.     textHandle=GetResource('TEXT', gUseAlternate ? 129 : 128);
  162.     if (textHandle==0L)
  163.         return;
  164.     if (*textHandle==0L)
  165.         LoadResource(textHandle);
  166.     if (*textHandle==0L)
  167.         return;
  168.     pos=0L;
  169.     theSize=SizeResource(textHandle);
  170.     do
  171.     {
  172.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  173.         DrawTheAboutString(theLine, &row, theCenter);
  174.     }
  175.     while (pos<theSize);
  176.     ReleaseResource(textHandle);
  177.     if (isColor)
  178.         ForeColor(redColor);
  179.     DrawTheAboutString(gMyName, &row, theCenter);
  180.     DrawTheAboutString(gMyOrg, &row, theCenter);
  181.     if (isColor)
  182.         ForeColor(blackColor);
  183.     TextMode(srcCopy);
  184.     TextSize(12);
  185.     TextFont(0);
  186. }
  187.  
  188. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  189. {
  190.     unsigned char    theChar;
  191.     
  192.     theLine[0]=0x00;
  193.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  194.         theLine[++theLine[0]]=theChar;
  195. }
  196.  
  197. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter)
  198. {
  199.     MoveTo(theCenter-StringWidth(theString)/2, *theRow);
  200.     DrawString(theString);
  201.     *theRow+=12;
  202. }
  203.